package test;

import static org.junit.Assert.*;
import Phase2.Node;
import java.util.TreeSet;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class testWhiteBoxInsertPointAlg 
{
	private final boolean rootAccess = false;
	private Node baseNode;
	private TreeSet<Node> hypeerWeb;
	
	
	@Before
	public void setUp()
	{
		baseNode = new Node();
		hypeerWeb = new TreeSet<Node>();
		hypeerWeb.add(baseNode);
	}
	
	@Test
	public void lastStateInsertion() throws InterruptedException
	{
		Node insertNode = new Node();
		Node checkNode = new Node();;
		baseNode.insert(insertNode);
		hypeerWeb.add(insertNode);
		assertEquals(0, insertNode.getParent(rootAccess).getId(rootAccess));
		
		for (int i = 0; i < 3; i++)
		{
			insertNode = new Node();
			baseNode.insert(insertNode);
			hypeerWeb.add(insertNode);
			if (i == 1)
			{ checkNode = insertNode; }
		}
		insertNode = new Node();
		checkNode.insert(insertNode);
		hypeerWeb.add(insertNode);
		
		assertEquals(3, checkNode.getId(rootAccess));
		assertEquals(1, insertNode.getParent(rootAccess).getId(rootAccess));
		for (int i = 0; i < 10; i++)
		{
			insertNode = new Node();
			baseNode.insert(insertNode);
			hypeerWeb.add(insertNode);
			if(i == 1)
			{ checkNode = insertNode; }
			
		}
		System.out.println(checkNode.getState(rootAccess) + " " + hypeerWeb.size());
		insertNode = new Node();
		checkNode.insert(insertNode);
		hypeerWeb.add(insertNode);

		assertEquals(7, checkNode.getId(rootAccess));
		assertEquals(0, insertNode.getParent(rootAccess).getId(rootAccess));
		
	}
	
	@Test
	public void upStateInsertion() throws InterruptedException
	{
		Node insertNode;
		Node checkNode = new Node();
		
		for (int i = 0; i < 2; i++)
		{
			insertNode = new Node();
			hypeerWeb.add(insertNode);
			baseNode.insert(insertNode);
			if (i == 1) 
			{ checkNode = insertNode; }
		}
		insertNode = new Node();
		checkNode.insert(insertNode);
		hypeerWeb.add(insertNode);
		assertEquals(1, insertNode.getParent(rootAccess).getId(rootAccess));
		
		for (int i = 0; i < 5; i++)
		{
			insertNode = new Node();
			baseNode.insert(insertNode);
			hypeerWeb.add(insertNode);
		}
		insertNode = new Node();
		checkNode.insert(insertNode);
		hypeerWeb.add(insertNode);

		assertEquals(1, insertNode.getParent(rootAccess).getId(rootAccess));
	}
	
	@After
	public  void tearDown()
	{
		hypeerWeb.clear();
	}
}
